package com.jwell.bigdata.base

import android.os.Bundle

/**
 * MVP模式下的基础Activity
 */
abstract class MVPBaseActivity<P : BasePresenter<*>> : BaseActivity(), IBaseView {

    var presenter: P? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        presenter = createPresenter()
        presenter?.attachView(this)
    }

    override fun onStart() {
        super.onStart()
        presenter?.start()
    }

    override fun onAttachedToWindow() {
        super.onAttachedToWindow()
    }

    abstract fun createPresenter(): P?

    override fun onStop() {
        super.onStop()
    }

    override fun onPause() {
        super.onPause()
    }

    override fun onRestart() {
        super.onRestart()
    }

    override fun onDestroy() {
        presenter?.unSubscrib()
        presenter?.deattachView()
        presenter = null
        super.onDestroy()
    }
}
